package cn.wxq.daily.empdailymgforserve.service.impl;

import cn.wxq.daily.empdailymgforserve.domain.SysUser;
import cn.wxq.daily.empdailymgforserve.mapper.IsysUserDao;
import cn.wxq.daily.empdailymgforserve.service.IsysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysUserServiceImpl implements IsysUserService{

    @Autowired
    private IsysUserDao sysUserDao;

    /**
     * 密码加密
     */
    @Autowired
    BCryptPasswordEncoder encoder;

    /**
     * 系统用户登录业务层
     *
     * @param username
     * @param password
     * @return
     */
    @Override
    public SysUser findByUsernameAndPassword(String username, String password) {

        SysUser sysUser = sysUserDao.findByUsername(username);
        if (sysUser != null && password.equals(sysUser.getPassword())) {
            return sysUser;
        } else {

            return null;
        }

    }

    /**
     * 条件查询
     * @param sysUser
     * @return
     */
    @Override
    public List<SysUser> findByPage(SysUser sysUser) {
        return sysUserDao.findByPage(sysUser);
    }

    /**
     * 查询所有系统用户信息
     *
     * @return
     */
    @Override
    public List<SysUser> findAllSysUser() {
        return sysUserDao.findAllSysUser();
    }

    /**
     * 新增
     * @param sysUser 用户信息
     * @return
     */
    @Override
    public int insertUser(SysUser sysUser) {
        return sysUserDao.insertUser(sysUser);
    }

    /**
     * 删除
     * @param userId
     * @return
     */
    @Override
    public int deleteById(Integer userId) {
        return sysUserDao.deleteById(userId);
    }

    /**
     * id查询
     * @param userId 用户ID
     * @return
     */
    @Override
    public SysUser selectUserById(Integer userId) {
        return sysUserDao.selectUserById(userId);
    }

    @Override
    public int updateUser(SysUser sysUser) {
        return sysUserDao.updateUser(sysUser);
    }
}
